package com.solution.startup;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import com.solution.constant.FileInitializationConstants;

public class InitServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -716566588226037466L;

	/**
	 * Default constructor.
	 */
	public InitServlet() {
		super();
	}

	/**
	 * Called only when a new instance of the servlet is created.
	 */
	public void init() throws ServletException {
		super.init();
		// Configure Logging first so that other initialization can log messages
		// there
		try {
			String logFilePath = getServletContext().getRealPath(
					FileInitializationConstants.FILE_LOG4J_INIT);
			PropertyConfigurator.configureAndWatch(logFilePath,
					FileInitializationConstants.LOG4J_WATCH_DELAY);
		} catch (Exception e) {
			// The only System.out in the Application
			System.out
					.println(FileInitializationConstants.ERR_INITIALIZING_LOG4J
							+ e);
		}
		Logger log = Logger.getLogger(InitServlet.class.getName());
		log.info(FileInitializationConstants.SUCCESS_LOG4J_INIT);
	}

	/**
	 * Called when the servlet instance is destroyed.
	 */
	public void destroy() {
		super.destroy();
	}
}
